package am.NotenProgramm.Frame;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

import am.NotenProgramm.Frame.Panels.GradePanel;
import am.NotenProgramm.Frame.Panels.SettingsPanel;
import am.NotenProgramm.Frame.Panels.StatisticsPanel;

public class MainFrame extends JFrame implements ActionListener {
	
	//MAINPANELS
	JPanel panelHeader = new JPanel();
	public static JDesktopPane panelMain = new  JDesktopPane();	
	
	//HEADERPANEL
	JButton buttonGrades = new JButton(GradePro.rb.getString("buttonGrades"));
	JButton buttonStatistics = new JButton(GradePro.rb.getString("buttonStatistics"));
	JButton buttonSettings = new JButton(GradePro.rb.getString("buttonSettings"));
	
	//PROGRAMMPANELS
	public GradePanel panelGrades;
	public SettingsPanel panelSettings;
	public StatisticsPanel panelStatistics;
	

	public MainFrame() {
		setSize(GradePro.mySettings.getWidth(), GradePro.mySettings.getHeight());
		setTitle(GradePro.mySettings.getStandartProfileName() + " - "+ GradePro.rb.getString("title") + " " + GradePro.versionNum);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(false);
		
		initUI();
		
		setAlwaysOnTop(false);
		setLocationRelativeTo(null);
		setVisible(true);
	}
		
	public void initUI() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		//HEADERPANEL
		setLayout(null);
		panelHeader.setLocation(0,0);
		panelHeader.setBackground(Color.LIGHT_GRAY);
		panelHeader.setSize((int)getSize().getWidth(),(int) (getSize().getHeight()*0.1));
		initHeader();
		add(panelHeader);
		
		//MAINPANEL
		panelMain.setLocation(0, panelHeader.getHeight());
		panelMain.setSize((int)getSize().getWidth(), (int)(getSize().getHeight()-panelHeader.getHeight()));
		add(panelMain);
		panelMain.setLayout(null);
		//3 MainPanels
		panelGrades = new GradePanel(panelMain.getSize());
		panelSettings = new SettingsPanel(panelMain.getSize());
		panelStatistics = new StatisticsPanel(panelMain.getSize());
		panelMain.add(panelGrades);
		panelMain.add(panelSettings);
		panelMain.add(panelStatistics);
		panelSettings.setVisible(false);
		panelStatistics.setVisible(true);
		panelGrades.setVisible(false);
	}

	private void initHeader() {
		panelHeader.setLayout(null);
		
		//Noten Button
		buttonGrades.setLocation(0,0);
		buttonGrades.setSize(panelHeader.getWidth()/3, panelHeader.getHeight());
		buttonGrades.addActionListener(this);
		panelHeader.add(buttonGrades);
		buttonGrades.setActionCommand("grades");
		
		//Statistiken Button
		buttonStatistics.setLocation(buttonGrades.getWidth(),0);
		buttonStatistics.setSize(panelHeader.getWidth()/3, panelHeader.getHeight());
		buttonStatistics.addActionListener(this);
		panelHeader.add(buttonStatistics);
		buttonStatistics.setActionCommand("statistics");
		
		//Einstellungen Button
		buttonSettings.setLocation(2*buttonGrades.getWidth(),0);
		buttonSettings.setSize(panelHeader.getWidth()/3, panelHeader.getHeight());
		buttonSettings.addActionListener(this);
		panelHeader.add(buttonSettings);
		buttonSettings.setActionCommand("settings");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("statistics")) {
			//JOptionPane.showMessageDialog(this, rb.getString("notSupportedYet"));
			panelGrades.setVisible(false);
			panelSettings.setVisible(false);
			panelStatistics.setVisible(true);
		}
		if (e.getActionCommand().equals("grades")) {
			panelGrades.setVisible(true);
			panelSettings.setVisible(false);
			panelStatistics.setVisible(false);
		}
		if(e.getActionCommand().equals("settings")){
			//JOptionPane.showMessageDialog(this, rb.getString("notSupportedYet"));
			panelGrades.setVisible(false);
			panelSettings.setVisible(true);
			panelStatistics.setVisible(false);
		}
		
	}

}
